﻿/*
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using FeedDotNet.Common;
using FeedDotNet;

namespace ConsoleApplication
{
    class RSSGenerator
    {
        const string rssName = "MovieRss.xml";
        private string dataDirectory = null;
        private Feed finalFeed;

        public RSSGenerator()
        {
            if (string.IsNullOrEmpty(dataDirectory))
                dataDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            if (File.Exists(Path.Combine(dataDirectory, rssName)))
            {
                finalFeed = FeedReader.Read(Path.Combine(dataDirectory, rssName));
                if (finalFeed == null)
                    finalFeed = new Feed();
            }
            else 
            {
                finalFeed = new Feed();
            }

            List<FeedItem> toDelete = new List<FeedItem>();

            foreach (FeedItem item in finalFeed.Items)
            {
                if (DateTime.Now.Subtract(item.Published.Value).Days > 14)
                    toDelete.Add(item);
            }

            foreach (FeedItem item in toDelete)
                finalFeed.Items.Remove(item);
        }

        public void MergeWithNewFeed(Feed newFeed)
        {
            if (newFeed == null)
                return;

            if (finalFeed == null)
                finalFeed = new Feed();

            Dictionary<string, FeedItem> uniquer = new Dictionary<string, FeedItem>();

            foreach (FeedItem item in finalFeed.Items)
            {
                uniquer.Add(item.Title, item);
            }

            foreach (FeedItem item in newFeed.Items)
            {
                FeedItem oldItem;
                if (uniquer.TryGetValue(item.Title, out oldItem))
                {
                    if (oldItem.Published < item.Published)
                        uniquer[item.Title] = item;
                }
                else
                {
                    if (!item.Published.HasValue)
                        item.Published = DateTime.Now;

                    uniquer.Add(item.Title, item);
                }
            }

            List<FeedItem> items = new List<FeedItem>(uniquer.Values);
            items.Sort(delegate (FeedItem i1, FeedItem i2)
            {
                return i2.Published.Value.CompareTo(i1.Published.Value);
            });

            finalFeed.Items = items;
        }

        public List<YahooNZBData> PrependWithData(Dictionary<string, YahooNZBData> newFeed)
        {
            if (newFeed == null)
                return null;

            if (finalFeed == null)
                finalFeed = new Feed();

            List<YahooNZBData> newItems = new List<YahooNZBData>();
            Dictionary<string, FeedItem> uniquer = new Dictionary<string, FeedItem>();

            foreach (FeedItem item in finalFeed.Items)
            {
                uniquer.Add(item.Title, item);
            }

            foreach (KeyValuePair<string, YahooNZBData> item in newFeed)
            {
                FeedItem oldItem;
                if (uniquer.TryGetValue(item.Key, out oldItem))
                {
                }
                else
                {
                    FeedItem feedItem = new FeedItem();
                    feedItem.Title = item.Key;
                    feedItem.Source = new Source(item.Value.imdbLink);
                    feedItem.Summary = string.Format("<img src='{2}' />{0}<br/><br/><a href='{1}'>{1}</a>", 
                        item.Value.description, 
                        item.Value.imdbLink, 
                        item.Value.movieDbLink);
                    feedItem.Published = DateTime.Now;

                    uniquer.Add(item.Key, feedItem);
                    newItems.Add(item.Value);
                }
            }

            List<FeedItem> items = new List<FeedItem>(uniquer.Values);
            items.Sort(delegate(FeedItem i1, FeedItem i2)
            {
                return i2.Published.Value.CompareTo(i1.Published.Value);
            });

            finalFeed.Items = items;

            return newItems;
        }

        public void SaveFeed()
        {
            File.WriteAllText(Path.Combine(dataDirectory, rssName), FeedDotNetExporter.ExportFeed(finalFeed));
        }

        public void SaveRemote()
        {
        }
    }
}
*/